﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CN.DBML;
using CN.Commons;

namespace CN.Import
{
    public partial class FormBusLineImport : Form
    {
        private CityNavigationDataContext _cNDC = new CityNavigationDataContext(); 
        public FormBusLineImport()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 导入公交路线
        /// 公交线路的格式：
        /// 线路名称,起点站,起点站首班时间,起点站末班时间,终点站,终点站首班时间,终点站末班时间,类型,上行,下行
        /// </summary>
        //private void importData()
        //{
        //    //得到提供的公交路线
        //    string data = this.tbxData.Text.Trim();
        //    string[] dataArr = data.Split(',');
        //    //新建公交路线实例
        //    BusLine busLine = new BusLine();
        //    DateTime dtNow = DateTime.Now;
        //    busLine.AddTime = dtNow;
        //    busLine.LineName = dataArr[0];
        //    busLine.FirstStation = dataArr[1];
        //    busLine.FirstBeginTime = dataArr[2];
        //    busLine.FirstEndTime = dataArr[3];
        //    busLine.LastStation = dataArr[4];
        //    busLine.LastBeginTime = dataArr[5];
        //    busLine.LastEndTime = dataArr[6];
        //    busLine.ScopeType = EnumHelper.ParseEnumValueByString<ScopeType>(dataArr[7]);
            
        //    //循环得到线路站点
        //    List<BusPassStation> bpStationList = new List<BusPassStation>();
        //    BusPassStation bpStation = null;
        //    int sn = 0;
        //    //上行
        //    foreach (string item in dataArr[8].Split('-'))
        //    {
        //        bpStation.LineName = dataArr[0];
        //        bpStation.SerialNum = sn;
        //        bpStation.StationName = item;
        //        bpStation.DirectionType = 1;
        //        bpStationList.Add(bpStation);
        //        sn++;
        //    }
        //    sn = 0;
        //    //下行
        //    foreach (string item in dataArr[9].Split('-'))
        //    {
        //        bpStation.LineName = dataArr[0];
        //        bpStation.SerialNum = sn;
        //        bpStation.StationName = item;
        //        bpStation.DirectionType = 2;
        //        bpStationList.Add(bpStation);
        //        sn++;
        //    }

        //    this._cNDC.BusLines.InsertOnSubmit(busLine);
        //    this._cNDC.BusPassStations.InsertAllOnSubmit(bpStationList);

        //    bool isSucceed = false;
        //    try
        //    {
        //        isSucceed = this._cNDC.SubmitChangesWithReturnValue();
        //    }
        //    catch (Exception)
        //    {
        //        MessageBox.Show("添加失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //    }
        //    if (isSucceed)
        //        MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        //    else
        //        MessageBox.Show("添加失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //}
    }
}
